package psd.model.Prolog.Converters;

import org.eclipse.jdt.core.dom.SingleVariableDeclaration;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologSingleVariableDeclarationConverter extends PrologConverter implements
IConverter<SingleVariableDeclaration>{

	public PrologSingleVariableDeclarationConverter(
			FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(SingleVariableDeclaration node) {
		  String id = idResolver.getID(node);
	        if(node.getParent().getNodeType() == 31 || node.getParent().getNodeType() == 70)
	        {
	            String args[] = {
	                id, getParentId(node), typeResolver.getTypeTerm(node.resolveBinding().getType()), quote(node.getName().getIdentifier()), this.getFilePath(node), this.getLineNumber(node)
	            };
	            writer.writeFact("paramDefT", args);
	            writer.writeFact("slT", new String[] {
	                id, Integer.toString(node.getStartPosition()), Integer.toString(node.getLength()), this.getFilePath(node), this.getLineNumber(node)
	            });
	            checkAndGenComments(node, id);
	        } else
	        if(node.getParent().getNodeType() == 12)
	        {
	            String args[] = {
	                id, getParentId(node), typeResolver.getTypeTerm(node.resolveBinding().getType()), quote(node.getName().getIdentifier()), this.getFilePath(node), this.getLineNumber(node)
	            };
	            writer.writeFact("paramDefT", args);
	            writer.writeFact("slT", new String[] {
	                id, Integer.toString(node.getStartPosition()), Integer.toString(node.getLength()), this.getFilePath(node), this.getLineNumber(node)
	            });
	            checkAndGenComments(node, id);
	        } else
	        {
	            throw new IllegalArgumentException((new StringBuilder("SingleVariableDeclaration (")).append(node).append(") has a parent of unexpected type:").append("\n").append(node.getParent()).append("\n").append("Maybe the implementation is inclomplete?").toString());
	        }
	        writeModifiers(node, node.getModifiers());
	        writeSourceLocationArgumentIdentifier(node, node.getName(), node.modifiers());
	        return false;
	}

}
